home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Programmation / jedit / jedit5.1.0install.exe / {app} / macros / Emacs / Emacs_Transpose_Lines.bsh < prev    next >
Text File  |  2013-07-28  |  1KB  |  46 lines

  1. /**
  2.  * Transpose line at caret with previous line, and move caret to next line.
  3.  *  Emulates Emacs "transpose-lines" command (without prefix argument support).
  4.  */
  5.  
  6. source (MiscUtilities.constructPath(dirname(scriptPath), "EmacsUtil.bsh"));
  7.  
  8. void emacsTransposeLines()
  9. {
  10.     caret = textArea.getCaretPosition();
  11.     if ((caret == 0) || atEndOfBuffer())
  12.     {
  13.         beep();
  14.         return;
  15.     }
  16.  
  17.     caretLine = textArea.getCaretLine();
  18.     lineStart = textArea.getLineStartOffset (caretLine);
  19.     lineEnd = textArea.getLineEndOffset (caretLine);
  20.     lineIndex = textArea.getLineOfOffset (caretLine);
  21.  
  22.     selection = new Selection.Range (lineStart, lineEnd);
  23.     line = textArea.getSelectedText(selection);
  24.  
  25.     // Get the location of the previous line
  26.  
  27.     textArea.goToPrevLine (false);
  28.     prevLineCaret = textArea.getCaretLine();
  29.     prevLineStart = textArea.getLineStartOffset (prevLineCaret);
  30.  
  31.     // Go back to the original location.
  32.     
  33.     textArea.setCaretPosition (caret);
  34.     
  35.     // Delete the line
  36.     
  37.     textArea.deleteLine();
  38.     
  39.     // Insert it in the new location.
  40.  
  41.     buffer.insert (prevLineStart, line);
  42. }
  43.  
  44. emacsTransposeLines();
  45.  
  46.